/*
 *Description:
 *User:Laohu
 *Created with Intellij IDEA 2025
 *Data:2025.05.13
 *Time:16:19
 */

import java.util.Scanner;
import java.util.Random;
public class Test{

    //猜数字小游戏
    public static void main7(String[] args) {
       Random random = new Random();
       int tem = random.nextInt(10);//生成0-10的随机数
        while(true) {
            Scanner scan = new Scanner(System.in);
            int n = scan.nextInt();
            if(tem > n)
                System.out.println("猜小了");
            else if(tem < n)
                System.out.println("猜大了");
            else
                break;
        }
        System.out.println("随机数为：" + tem);
    }

    //打印1-100的素数
    public static void main6(String[] args) {
        int i = 0;
        for(i = 1;i <= 100;i+=2){
            int j = 0;
            for(j = 2;j <= Math.sqrt(i);j++){
                if(i % j == 0)
                    break;
            }
                if(j > Math.sqrt(i))
                    System.out.print(i + " ");
        }
    }

    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
    public static void main5(String[] args) {
        int i = 0;
        double sum = 0;
        int flat=1;
        for(i = 1;i <= 100;i++){
            sum += (1.0 * flat) / i;
            flat = -flat;
        }
        System.out.println("sum = " + sum);
    }

    //求两个数的最大公约数
    public static void main4(String[] args) {
        int a = 20;
        int b = 30;
        int tem = a % b;
        while(tem != 0){
            a = b;
            b = tem;
            tem = a % b;
        }
        System.out.println(b);
    }

    //计算1-100中9出现的次数
    public static void main3(String[] args) {
       int i = 0;
       int cnt=0;
       for(i = 1;i <= 100; i++){
           if(i % 10 == 9)
               cnt++;
           if(i % 10 == 9)
               cnt++;
       }
        System.out.println(cnt);
    }

    //输出1000-2000的闰年
    public static void main2(String[] args) {
        int i = 0;
        for(i = 1000;i <= 2000;i += 4){
            if(i % 400 == 0 || ( i % 4 == 0 && i % 100 != 0))
                System.out.print(i+" ");
        }

    }

    //打印水仙花数
    public static void main1(String[] args){
      int i=0;
      for(i = 100;i < 999; i++)
      {
          int cnt = 0;
          int tem = i;
          while(tem != 0) {
              cnt++;
              tem /= 10;
          }
            tem = i;
          int sum = 0;
          while(tem != 0) {
              sum += Math.pow(tem % 10,cnt);
              tem /= 10;
          }
          if(sum == i) {
              System.out.println(cnt+" 位数的水仙花数为：" + i);
          }
      }
    }
}
